package com.andy.war;

import com.andy.war.obj.Position;
import com.andy.war.obj.battle.Army;
import com.andy.war.obj.battle.BattleContext;
import com.andy.war.util.Log;
import com.andy.war.vo.MonsterVO;
import com.andy.war.vo.RoleVO;

public class GameWar {

	BattleContext battleContext;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new GameWar().initGame().startGame();
	}
	
	public GameWar initGame(){
		Log.p("init game...");
		
		battleContext = buildContext();
		
		return this;
	}
	
	public void startGame(){
		new Thread(new Looper()).start();
	}
	
	public class Looper implements Runnable{

		private int flip = 2;
		private boolean stop = false;
		@Override
		public void run() {
			while(!stop){
				try {
					doInLooper();
					Thread.sleep(1000*flip);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
		
	}
	
	public void doInLooper(){
		battleContext.fight();
	}
	
	
	private BattleContext buildContext() {
		BattleContext battleContext = new BattleContext();
		RoleVO role1 = new RoleVO(1, "andy");
		RoleVO role2 = new RoleVO(2, "vincent");
		Army attacker1 = new Army(role1);
		attacker1.setPosition(new Position(1,2));
		Army attacker2 = new Army(role2);
		attacker2.setPosition(new Position(4,2));
		battleContext.addAttacker(attacker1).addAttacker(attacker2);
		MonsterVO monster1 = new MonsterVO(1, "monster1");
		MonsterVO monster2 = new MonsterVO(2, "monster1");
		Army defender1 = new Army(monster1);
		attacker1.setPosition(new Position(1,20));
		Army defender2 = new Army(monster2);
		attacker1.setPosition(new Position(4,20));
		battleContext.addDefender(defender1).addDefender(defender2);
		
		
		return battleContext;
	}
	
	
}
